package hqb.dev.webdeploy.flow;

import cn.hutool.json.JSONObject;
import lombok.Data;

import java.util.HashMap;

/**
 * @author HQB--2024-04-22
 **/
@Data
public class FlowStepCommandEnv {
    private boolean system;
    private JSONObject cunstom;

    public FlowStepCommandEnv(JSONObject env) {
        this.system = env.getBool("system", false);
        if (this.system) {
            this.cunstom = env.getJSONObject("custom");

        }
    }

    public String[] getEnvs() {
        HashMap<String, String> envs = new HashMap<>();
        if (this.system) {
            envs.putAll(System.getenv());
        }
        if (this.cunstom != null) {
            envs.putAll(this.cunstom.toBean(HashMap.class));
        }
        return envs.entrySet().stream().map(x -> x.getKey() + "=" + x.getValue()).toArray(String[]::new);
    }
}
